/*     */ package cn.zzuisa.news.servlet;
/*     */ 
/*     */ import cn.zzuisa.news.entity.Page;
/*     */ import cn.zzuisa.news.entity.User;
/*     */ import cn.zzuisa.news.enums.CommonEnums;
/*     */ import cn.zzuisa.news.form.RegisterSimpleForm;
/*     */ import cn.zzuisa.news.form.UserEditForm;
/*     */ import cn.zzuisa.news.service.UserService;
/*     */ import cn.zzuisa.news.service.impl.UserServiceImpl;
/*     */ import cn.zzuisa.news.util.JsonUtil;
/*     */ import cn.zzuisa.news.util.ResultVOUtil;
/*     */ import com.google.gson.Gson;
/*     */ import com.google.gson.JsonObject;
/*     */ import com.google.gson.JsonParser;
/*     */ import java.io.IOException;
/*     */ import java.util.List;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.annotation.WebServlet;
/*     */ import javax.servlet.http.HttpServlet;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ @WebServlet(name = "user", urlPatterns = {"/user"}, asyncSupported = true)
/*     */ public class UserServlet
/*     */   extends HttpServlet
/*     */ {
/*  36 */   private UserService userServiceImpl = new UserServiceImpl();
/*     */ 
/*     */   
/*     */   protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
/*  40 */     String method = req.getParameter("method");
/*     */ 
/*     */     
/*  43 */     if (method.equals("edit")) {
/*  44 */       String json = JsonUtil.getStrResponse(req);
/*  45 */       JsonObject edit = (new JsonParser()).parse(json).getAsJsonObject();
/*  46 */       UserEditForm userEditForm = (UserEditForm)(new Gson()).fromJson(edit, UserEditForm.class);
/*  47 */       if (this.userServiceImpl.edit(userEditForm)) {
/*  48 */         resp.getWriter().println(JsonUtil.setData(ResultVOUtil.success(CommonEnums.SUCCESS)));
/*     */       } else {
/*  50 */         resp.getWriter().println(JsonUtil.setData(ResultVOUtil.failed(CommonEnums.PARAM_ERROR)));
/*     */       } 
/*     */     } 
/*  53 */     if (method.equals("register_simple")) {
/*  54 */       String json = JsonUtil.getStrResponse(req);
/*  55 */       RegisterSimpleForm registerSimpleForm = (RegisterSimpleForm)(new Gson()).fromJson(json, RegisterSimpleForm.class);
/*  56 */       if (this.userServiceImpl.register(registerSimpleForm)) {
/*  57 */         resp.getWriter().println(JsonUtil.setData(ResultVOUtil.success(CommonEnums.SUCCESS)));
/*     */       } else {
/*  59 */         resp.getWriter().println(JsonUtil.setData(ResultVOUtil.failed(CommonEnums.PARAM_ERROR)));
/*     */       } 
/*     */     } 
/*     */     
/*  63 */     if (method.equals("detail_page")) {
/*  64 */       String key = req.getParameter("key");
/*  65 */       if (key != null)
/*  66 */         req.setAttribute("key", key); 
/*  67 */       User user = this.userServiceImpl.findByUsername(((User)req.getSession().getAttribute("user")).getUsername());
/*  68 */       System.out.println("userPoint:" + user.getPoint());
/*  69 */       req.setAttribute("user", user);
/*  70 */       req.getRequestDispatcher("WEB-INF/ftl/user/detail.ftl").forward(req, resp);
/*     */     } 
/*  72 */     if (method.equals("list")) {
/*     */       Integer size, current;
/*     */       
/*  75 */       Page page = null;
/*  76 */       List<User> users = null;
/*     */       try {
/*  78 */         current = Integer.valueOf(Integer.parseInt(req.getParameter("page")));
/*  79 */         size = Integer.valueOf(Integer.parseInt(req.getParameter("size")));
/*  80 */       } catch (NumberFormatException e) {
/*  81 */         current = Integer.valueOf(1);
/*  82 */         size = Integer.valueOf(10);
/*     */       } 
/*  84 */       page = this.userServiceImpl.pagelist(current, size);
/*  85 */       page.setPageNo(current.intValue());
/*  86 */       req.setAttribute("lists", page);
/*  87 */       req.getRequestDispatcher("WEB-INF/ftl/user/list.ftl").forward(req, resp);
/*     */     } 
/*  89 */     if (method.equals("edit_page")) {
/*  90 */       req.getRequestDispatcher("WEB-INF/ftl/user/edit_page.ftl").forward(req, resp);
/*     */     }
/*  92 */     if (method.equals("state")) {
/*  93 */       Integer id = Integer.valueOf(Integer.parseInt(req.getParameter("id")));
/*  94 */       Integer key = Integer.valueOf(Integer.parseInt(req.getParameter("key")));
/*     */       
/*  96 */       System.out.println("id:" + id + " key:" + key);
/*  97 */       if (this.userServiceImpl.editState(id, key)) {
/*  98 */         resp.getWriter().println(JsonUtil.setData(ResultVOUtil.success()));
/*     */       } else {
/* 100 */         resp.getWriter().println(JsonUtil.setData(ResultVOUtil.failed(CommonEnums.PARAM_ERROR)));
/*     */       } 
/*     */     } 
/*     */   }
/*     */ }


/* Location:              /Users/frank/Desktop/admin/WEB-INF/classes/!/cn/zzuisa/news/servlet/UserServlet.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.0.7
 */